package com.maoxx.humanresourcemanage_service.controller;

import com.maoxx.humanresourcemanage_service.dto.ResponseDTO;
import com.maoxx.humanresourcemanage_service.entity.Insurance;
import com.maoxx.humanresourcemanage_service.service.InsuranceService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @className: InsuranceController
 * @author: Maoxx
 * @date: 2024/11/13 11:39
 * @Version: 1.0
 * @description:
 */

@RestController
@RequestMapping("/insurance")
public class InsuranceController {

    @Resource
    private InsuranceService insuranceService;

    @ApiOperation("分页条件查询")
    @GetMapping
    public ResponseDTO list(@RequestParam(defaultValue = "1") Integer current,
                            @RequestParam(defaultValue = "10") Integer size,
                            @RequestParam(defaultValue = "") String name) {

        /*System.out.println("当前页：" + current);
        System.out.println("每页显示条数：" + size);
        System.out.println("查询条件：" + name);
        System.out.println("=============================");*/
        return insuranceService.list(current, size, name);
    }

    @ApiOperation("数据导出接口")
    @GetMapping("/export")
    public ResponseDTO export(HttpServletResponse response) throws IOException {
        return this.insuranceService.export(response);
    }

    @ApiOperation("数据导入接口")
    @PostMapping("/import")
    public ResponseDTO imp(MultipartFile file) throws IOException {
        return this.insuranceService.imp(file);
    }

    @ApiOperation("查询")
    @GetMapping("/{id}")
    public ResponseDTO findById(@PathVariable Integer id) {
        return this.insuranceService.findById(id);
    }

    @ApiOperation("为员工设置社保")
    @PostMapping("/set")
    public ResponseDTO setInsurance(@RequestBody Insurance insurance) {
        return this.insuranceService.setInsurance(insurance);
    }

    @ApiOperation("查询")
    @GetMapping("/staff/{id}")
    public ResponseDTO findByStaffId(@PathVariable Integer id) {
        return this.insuranceService.findByStaffId(id);
    }


}
